package com.zhuhai.entity;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
 * @author zhuhai
 */
@Entity
@NamedEntityGraph(name = "pnr.all",
        attributeNodes = {
            @NamedAttributeNode("passenger")
        })
@Table(name = "t_pnr")
public class Pnr implements Serializable {
    /**
     * 默认的序列化 id.
     */
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String pnr;

    private Integer passengeTotal;

    private Date createTime;

    private Date updateTime;

    private String issueOfficeCode;

    public List<Passenger> getPassenger() {
        return passenger;
    }

    public void setPassenger(List<Passenger> passenger) {
        this.passenger = passenger;
    }

    /**
     *
     */
    @OneToMany(mappedBy="pnr")
    /**
     * 級聯刪除
     */
    @Cascade({CascadeType.PERSIST,CascadeType.REMOVE})
    private List<Passenger> passenger;

    @OneToMany(mappedBy="pnr", fetch=FetchType.LAZY)
    /**
     * 級聯刪除,級聯保存
     */
    @Cascade({CascadeType.PERSIST, CascadeType.REMOVE})
    @Fetch(FetchMode.SUBSELECT)
    private List<Segment> segment;

    public List<Segment> getSegment() {
        return segment;
    }

    public void setSegment(List<Segment> segment) {
        this.segment = segment;
    }

    public Integer getId() {
        return id;
    }

    public void setId(final Integer id) {
        this.id = id;
    }

    public String getPnr() {
        return pnr;
    }

    public void setPnr(final String pnr) {
        this.pnr = pnr;
    }

    public Integer getPassengeTotal() {
        return passengeTotal;
    }

    public void setPassengeTotal(final Integer passengeTotal) {
        this.passengeTotal = passengeTotal;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(final Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(final Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getIssueOfficeCode() {
        return issueOfficeCode;
    }

    public void setIssueOfficeCode(final String issueOfficeCode) {
        this.issueOfficeCode = issueOfficeCode;
    }
}
